package com.drophair.jspwork.Servlet;

import com.drophair.jspwork.bean.Sqlgoods;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Vector;

@WebServlet(name = "GoodsServlet", value = "/GoodsServlet")
public class GoodsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        Sqlgoods sqlgoods=new Sqlgoods();
        try {
            Vector<Vector<String>> vectors=sqlgoods.getGoodsInfo();
            for(Vector vector:vectors){
                for(int i=0;i<vector.size();i++){
                    System.out.println("VECTOR 是："+vector.get(i));
                }
            }
            request.setAttribute("goods",vectors);
            request.getRequestDispatcher("/common/index.jsp").forward(request,response);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        super.doGet(request,response);
    }
}
